/*
 * @Description: 发布详情
 * @Author: iamsmiling
 * @Date: 2021-06-13 17:12:05
 * @LastEditTime: 2021-06-15 18:00:56
 */
import 'dart:ui';

import 'package:credit_business_circle/R/R.dart';
import 'package:credit_business_circle/components/button/animated_button.dart';
import 'package:credit_business_circle/components/image/chimera_image.dart';
import 'package:credit_business_circle/components/modal/message_board_modal.dart';
import 'package:credit_business_circle/pages/publish_square/children/publish_center/dialog/show_copy_message_dialog.dart';
import 'package:credit_business_circle/pages/publish_square/children/publish_detail/section/author_contact_card.dart';
import 'package:credit_business_circle/pages/publish_square/children/publish_detail/section/source_card.dart';
import 'package:credit_business_circle/pages/publish_square/children/publish_detail/section/source_demander_card.dart';
import 'package:credit_business_circle/pages/publish_square/children/publish_detail/section/source_description_card.dart';
import 'package:credit_business_circle/pages/publish_square/children/publish_detail/section/source_extra_info_card.dart';
import 'package:credit_business_circle/pages/publish_square/children/publish_detail/section/source_provider_card.dart';
import 'package:credit_business_circle/routes/app_routes.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class TopicDetailPage extends StatelessWidget {
  const TopicDetailPage({Key? key}) : super(key: key);
  Future openDialog(BuildContext ctx) {
    RenderBox renderBox = ctx.findRenderObject() as RenderBox;
    Rect box = renderBox.localToGlobal(Offset.zero) & renderBox.size;
    double top = GetPlatform.isAndroid ? box.center.dy : box.topCenter.dy;
    return showDialog(
        context: ctx,
        barrierColor: R.color.transparent,
        builder: (BuildContext context) {
          return DefaultTextStyle(
            style: TextStyle(
                fontSize: R.dimen.sp16,
                color: R.color.ffffffff,
                fontWeight: FontWeight.w500),
            child: Stack(
              children: [
                Positioned(
                  top: top - R.dimen.dp6,
                  right: R.dimen.width - box.bottomCenter.dx - R.dimen.dp9,
                  child: Container(
                    child: Column(
                      children: [
                        Container(
                            decoration: BoxDecoration(
                                color: R.color.ff4c4c4c,
                                borderRadius:
                                    BorderRadius.circular(R.dimen.sp5)),
                            child: Column(
                              children: [
                                Container(
                                  decoration: BoxDecoration(
                                      border: Border(
                                          bottom: BorderSide(
                                              width: .5,
                                              color: R.color.ff777777))),
                                  padding: EdgeInsets.symmetric(
                                      horizontal: R.dimen.dp28,
                                      vertical: R.dimen.dp18),
                                  child: Row(
                                    children: [
                                      Container(
                                        margin: EdgeInsets.only(
                                            right: R.dimen.dp10),
                                        child: Image.asset(R.image.shareLink),
                                      ),
                                      Text("分享链接")
                                    ],
                                  ),
                                ),
                                GestureDetector(
                                  onTap: () => showCopyMessageDialog(context),
                                  child: Container(
                                    decoration: BoxDecoration(
                                        border: Border(
                                            bottom: BorderSide(
                                                width: .5,
                                                color: R.color.ff777777))),
                                    padding: EdgeInsets.symmetric(
                                        horizontal: R.dimen.dp28,
                                        vertical: R.dimen.dp18),
                                    child: Row(
                                      children: [
                                        Container(
                                          margin: EdgeInsets.only(
                                              right: R.dimen.dp10),
                                          child: Image.asset(R.image.linkCopy),
                                        ),
                                        Text("复制信息")
                                      ],
                                    ),
                                  ),
                                ),
                                GestureDetector(
                                  onTap: () => Get.toNamed(AppRoutes.report),
                                  child: Container(
                                    padding: EdgeInsets.symmetric(
                                        horizontal: R.dimen.dp28,
                                        vertical: R.dimen.dp18),
                                    child: Row(
                                      children: [
                                        Container(
                                          margin: EdgeInsets.only(
                                              right: R.dimen.dp10),
                                          child: Image.asset(R.image.report),
                                        ),
                                        Text("我要举报")
                                      ],
                                    ),
                                  ),
                                ),
                              ],
                            ))
                      ],
                    ),
                  ),
                ),
                Positioned(
                  top: top - R.dimen.dp12,
                  right: R.dimen.width - box.bottomCenter.dx,
                  child: Image.asset(R.image.triangle),
                ),
              ],
            ),
          );
        });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: R.color.ffffffff,
      body: CustomScrollView(
        physics: ClampingScrollPhysics(),
        slivers: [
          SliverAppBar(
            iconTheme: IconThemeData(color: R.color.ffffffff),
            title: Text(
              "发布效果预览",
              style: TextStyle(color: R.color.ffffffff),
            ),
            actions: [
              Builder(builder: (BuildContext context) {
                return IconButton(
                    onPressed: () => openDialog(context),
                    icon: Image.asset(
                      R.image.moreAction,
                      color: R.color.ffffffff,
                    ));
              }),
            ],
            pinned: true,
            expandedHeight: R.dimen.dp70,
            flexibleSpace: Image.asset(
              R.image.calenderBg,
              fit: BoxFit.fitWidth,
            ),
          ),
          SliverToBoxAdapter(
            child: Container(
              child: Stack(
                children: [
                  Image.asset(
                    R.image.calenderBg,
                    // fit: BoxFit.fitWidth,
                    width: R.dimen.width,
                    height: R.dimen.dp70,
                    fit: BoxFit.fill,
                  ),
                  Container(
                      margin: EdgeInsets.symmetric(horizontal: R.dimen.dp13),
                      child: SourceTopicCard())
                ],
              ),
            ),
          ),
          SliverToBoxAdapter(
            child: Container(
              margin: EdgeInsets.only(
                  left: R.dimen.dp13,
                  right: R.dimen.dp13,
                  top: R.dimen.dp20,
                  bottom: R.dimen.dp24),
              child: Row(
                children: [
                  Container(
                    margin: EdgeInsets.only(right: R.dimen.dp10),
                    child: ChimeraImage(
                        width: R.dimen.dp40,
                        height: R.dimen.dp40,
                        src:
                            "https://i.loli.net/2021/04/13/2VkqWFU5sxwSQcu.png"),
                  ),
                  Expanded(
                      child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        children: [
                          Text(
                            "不会游泳的鱼",
                            style: TextStyle(fontSize: R.dimen.sp13),
                          ),
                          Container(
                            margin: EdgeInsets.only(
                                left: R.dimen.dp10, right: R.dimen.dp10),
                            child: Image.asset(R.image.realNameAuthed),
                          ),
                          Image.asset(R.image.jobTag)
                        ],
                      ),
                      Container(
                        child: Text(
                          "总经理 | 杭州叮咚网络科技有限公司",
                          style: TextStyle(
                              fontSize: R.dimen.sp11, color: R.color.ff999999),
                        ),
                      )
                    ],
                  ))
                ],
              ),
            ),
          ),
          SliverToBoxAdapter(
            child: Container(
                margin: EdgeInsets.symmetric(horizontal: R.dimen.dp13),
                child: AuthorContactCard()),
          ),
          SliverToBoxAdapter(
            child: Container(
                margin: EdgeInsets.symmetric(horizontal: R.dimen.dp13),
                child: SourceProviderCard()),
          ),
          SliverToBoxAdapter(
            child: Container(
                margin: EdgeInsets.symmetric(horizontal: R.dimen.dp13),
                child: SourceDemanderCard()),
          ),
          SliverToBoxAdapter(
            child: Container(
                margin: EdgeInsets.symmetric(horizontal: R.dimen.dp13),
                child: SourceDescriptionCard()),
          ),
          SliverToBoxAdapter(
            child: Container(
              margin: EdgeInsets.symmetric(horizontal: R.dimen.dp13),
              child: SourceExtraInfoCard(),
            ),
          ),
          SliverToBoxAdapter(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Divider(
                  thickness: R.dimen.dp10,
                  height: R.dimen.dp10,
                  color: R.color.fff5f5f5,
                ),
                Container(
                  margin: EdgeInsets.only(
                      left: R.dimen.dp13,
                      right: R.dimen.dp13,
                      top: R.dimen.dp25),
                  child: Text(
                    "全部留言",
                    style: TextStyle(
                        fontWeight: FontWeight.w600,
                        fontSize: R.dimen.sp16,
                        color: R.color.ff111111),
                  ),
                ),
              ],
            ),
          ),
          SliverList(
              delegate:
                  SliverChildBuilderDelegate((BuildContext context, int i) {
            return Container(
              margin: EdgeInsets.only(top: R.dimen.dp20),
              padding: EdgeInsets.symmetric(horizontal: R.dimen.dp13),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    margin: EdgeInsets.only(right: R.dimen.dp12),
                    child: ChimeraImage(
                      src: "https://i.loli.net/2021/04/15/yDbnXQmZTH6tu5I.png",
                      width: R.dimen.dp26,
                      height: R.dimen.dp26,
                      borderRadius: BorderRadius.circular(R.dimen.dp13),
                    ),
                  ),
                  Expanded(
                      child: Container(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          "麻花腾",
                          style: TextStyle(
                            fontSize: R.dimen.sp13,
                            color: R.color.ff555555,
                          ),
                        ),
                        Container(
                          margin: EdgeInsets.only(top: R.dimen.dp7),
                          child: Text(
                            "我需要您的资源，请速度联系我！",
                            style: TextStyle(
                                fontSize: R.dimen.sp15,
                                color: R.color.ff111111),
                          ),
                        ),
                        Container(
                          margin: EdgeInsets.only(
                              top: R.dimen.dp10, bottom: R.dimen.dp24),
                          child: Text(
                            "2021-04-07 12:30",
                            style: TextStyle(
                              color: R.color.ffaaaaaa,
                              fontSize: R.dimen.sp12,
                            ),
                          ),
                        ),
                        Divider(
                          height: 1,
                        )
                      ],
                    ),
                  ))
                ],
              ),
            );
          }, childCount: 6))
        ],
      ),
      bottomNavigationBar: Container(
        height: kBottomNavigationBarHeight + R.dimen.dp13,
        alignment: Alignment.center,
        padding: EdgeInsets.only(
          left: R.dimen.dp18,
          right: R.dimen.dp15,
          bottom: R.dimen.dp13,
        ),
        decoration: BoxDecoration(color: R.color.ffffffff, boxShadow: [
          BoxShadow(
              offset: Offset(0, 1),
              blurRadius: 5,
              spreadRadius: 1,
              color: Colors.black.withAlpha(30))
        ]),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Container(
              margin: EdgeInsets.only(right: R.dimen.dp32, top: R.dimen.dp12),
              child: Column(
                children: [
                  AnimatedButton(
                      onPressed: () => Future.value(true),
                      activeWidget: Image.asset(
                        R.image.uncollect,
                        color: Colors.red,
                      ),
                      deactiveWidget: Image.asset(R.image.uncollect)),
                  Container(
                    margin: EdgeInsets.only(top: R.dimen.dp8),
                    child: Text(
                      "收藏",
                      style: TextStyle(
                          fontSize: R.dimen.sp11, color: R.color.ff111111),
                    ),
                  )
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.only(top: R.dimen.dp12),
              child: Column(
                children: [
                  GestureDetector(
                    onTap: () =>
                        showMessageBoardModal(context, onMessageTap: (_) => ""),
                    child: Image.asset(R.image.leaveMessage),
                  ),
                  Container(
                    margin: EdgeInsets.only(top: R.dimen.dp8),
                    child: Text(
                      "留言",
                      style: TextStyle(
                          fontSize: R.dimen.sp11, color: R.color.ff111111),
                    ),
                  )
                ],
              ),
            ),
            Expanded(
                child: GestureDetector(
              behavior: HitTestBehavior.translucent,
              onTap: () =>
                  Get.toNamed(Get.currentRoute + AppRoutes.companyProfile),
              child: Container(
                margin: EdgeInsets.only(left: R.dimen.dp28),
                padding: EdgeInsets.symmetric(vertical: R.dimen.dp6),
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(R.dimen.sp5),
                    gradient: LinearGradient(
                        colors: [R.color.ff1bbd8d, R.color.ff14ca94])),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    ChimeraImage(
                      src: "",
                      width: R.dimen.dp25,
                      height: R.dimen.dp25,
                      borderRadius: BorderRadius.circular(R.dimen.dp25 / 2),
                      fit: BoxFit.fill,
                    ),
                    Container(
                      margin: EdgeInsets.only(left: R.dimen.dp10),
                      child: Text(
                        "联系他",
                        style: TextStyle(
                            fontSize: R.dimen.sp14,
                            color: R.color.ffffffff,
                            fontWeight: FontWeight.w500),
                      ),
                    ),
                  ],
                ),
              ),
            ))
          ],
        ),
      ),
    );
  }
}
